#ifndef YC_H_INCLUDED
#define YC_H_INCLUDED

#include "act_types.h"
#include "mhdef.h"
#include "ccycle.h"
#include "feedback.h"
#include "timer.h"

typedef struct _YC YC;

struct _YC
{
    uchar state[4];         /* 0-系统１纱嘴状态;bit0-7为1-8号纱嘴
                               1-系统２纱嘴状态；0-打下；１－复位
                            */
    uchar group_state[4];
    uchar state_bk[4];      /* 备份状态 */
    CCYCLE cycle;
    CCYCLE reset_cycle;
    CHECK_TIMER timer;

    int (*exec)(MH_UDP *pudp, ActType type, uchar *state);
};


YC *yc_new();
void yc_set_cycle(YC *yc, CCYCLE *cycle, CCYCLE *reset_cycle);
int yc_exec(MH_UDP *pudp, YC *yc, ActType type, int group, int num);
int yc_exec_group(MH_UDP *pudp, YC *yc, int group);


int yc_exec_cycle(MH_UDP *pudp, void *user_data);
int yc_restore(MH_UDP *pudp, void *user_data);
void yc_start_timer(YC *yc, TIMEOUT_FUNC pfunc, BOOL now);
int yc_exec_timer(MH_UDP *pudp, YC *yc);
void yc_stop_cycle(YC *yc);
int yc_check_error(MH_UDP *pudp, void *user_data);

BOOL yc_reset_complete(YC *yc);

uchar yc_convert_state(YC *yc, uchar state);
void yc_set_state(YC *yc, uchar *state, int size);
void yc_get_state(YC *yc, uchar *state, int size);
int yc_encount_error(YC *yc, FEEDBACK *fb);
CCYCLE* yc_get_cycle(YC *yc);
void yc_set_group_state(YC *yc, uchar group_state, uchar group);
uchar yc_get_group_state(YC *yc, uchar group);

BOOL yc_need_restore(YC *yc);

#endif // YC_H_INCLUDED
